package card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 张宇田
 * Date: 2025-08-20
 * Time: 17:43
 */
public class Game {
    public static final String[] SUITS = {"♠","♥","♦","♣"};

    //先买一副拍回来
    public  List<Card> createCard(){

        //算是一张牌了 然后我们把牌坊到一起
        List<Card> card = new ArrayList<>();
        List<List<Card>> cards = new ArrayList<>();

        for (int i = 0 ; i<4; i++){
            for (int j = 1; j <= 13 ; j++){
                Card card1 = new Card(j,SUITS[i]);
                card.add(card1);
            }
        }

        return card;
    }

    //洗牌
    public void shuffle( List<Card> card ){
        Random rand = new Random();
        //先生成随机下标 然后交换位置
        /*for (int i = 0 ; i < 52 ; i++){
            int randIndex = rand.nextInt(i);
            这里我们正着交换 不方便
        }*/
        //从最后 往前换
        for (int i = card.size() -1 ; i > 0 ;i--){
            int randIndex = rand.nextInt(i);
            swap(card,i,randIndex);
        }


    }

    private void swap(List<Card> card , int i , int index){
        Card tmp = card.get(i);
        /*card.get(i) = card.get(index);
        get只是把牌取出来了， set才是放
        card.get(index) = tmp;*/
        card.set(i,card.get(index));
        card.set(index,tmp);
    }

    //现在我要玩牌了  三个人，每个人轮流抓 ,每个人 共5 张牌
    public List<List<Card>> play(List<Card> card ){

        List<List<Card>> gamer = new ArrayList<>();

        List<Card> hand0 = new ArrayList<>();
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();

        gamer.add(hand0);
        gamer.add(hand1);
        gamer.add(hand2);

        for (int i = 0 ; i < 5; i++){
            for (int j = 0 ; j<3 ;j++){
                //把牌 放到hand中
                gamer.get(j).add(card.get(0)) ;
                card.remove(0);
            }
        }
        return gamer;
    }
}
